<?php
if($_REQUEST[excel] == 'true'){
	header("Content-type: application/vnd.ms-excel");
	header("Content-Disposition: attachment; cirTotal-".$_REQUEST[fecha].".xls");
}

require("../services/class/listaPlanillasCirugias.php");

$cirugias = new class_listaPlanillasCirugias();
$params = array();
$fecha = $params[0]->fecha_asignada = $_REQUEST['fecha'];
$params[0]->canceladas == '0';
$result = $cirugias->method_getCirTotal($params,$error);
$data = $result->values;
?>
<html>
<head>
	<title>CIRUGIAS CIERRE</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="Content-Language" content="es-es" />
	<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
	<table width="1000px" align="center" border="0">
	<tr>
		<td>
			<font class="titulo">SOFAMBAR:<br/>CIERRE DE CIRUGIAS DEL DIA <?php echo $result->fecha ?></font>
			<br/><br/>
		</td>
	</tr>
	</table>
	<table width="1000px" align="center" border="1" cellpadding="0" cellspacing="0">
	<tr class='subtitulo' align="center">
		<td width='200'>
			PACIENTE
			<br/><br/>
		</td>		
		<td width='50'>
			HORA
		</td>	
		<td width='70'>
			MEDICO
		</td>		
		<td width='100'>
			REFERENCIA
		</td>			
		<td width='10'>
			OJO
		</td>
		<td width='300'>
			CIRUGIA
		</td>	
		<td width='200'>
			OBRA SOCIAL
		</td>
		<td width="200">
			OBSERVACION
		</td>
		<td width='50'>
			CIERRE
		</td>		
		<td width='90'>
			A COBRAR
		</td>		
		<td width='80'>
			COBRADO
		</td>						
	</tr>
	<?php
		$totalCirugias = 0;
		$totalImporte=0;
		$totalPlus=0;
		foreach ($data as $row){
			$extras = $cirugias->method_getExtras($row->cod_turno);
			$extras = $extras->values;
			if($row->obra_social == '' OR $row->obra_social == 'PARTICULARES, PARTICULARES'){
				$row->obra_social = 'PARTICULARES';
				$extras[0]->plus = $extras[0]->importe;
				$extras[0]->importe = '';
				}
			$totalImporte+=$extras[0]->importe;
			$totalPlus+=$extras[0]->plus;
			$totalCirugias++;
	?>
	<tr class='elemento'>
			<td><?php echo $row->paciente ?>&nbsp;</td>		
			<td align='center'><?php echo $row->hora_citado ?>&nbsp;</td>
			<td><?php echo $row->medico ?>&nbsp;</td>
			<td><?php echo $row->referencia ?>&nbsp;</td>
			<td align='center'><?php echo $row->ojo ?>&nbsp;</td>
			<td><?php echo $row->cirugia ?>&nbsp;</td>
			<td><?php echo $row->obra_social ?>&nbsp;</td>
			<td><?php echo $row->observaciones_factura ?>&nbsp;</td>		
			<td align="center"><?php if($row->pago == 'A')echo 'SI'; else echo 'NO';?>&nbsp;</td>
			<td align="right"><?php echo number_format($extras[0]->importe,2,',','.') ?>&nbsp;</td>
			<td align="right"><?php echo number_format($extras[0]->plus,2,',','.')?>&nbsp;</td>
	</tr>
	<?php	
		}
	?>
	</table>
	<table width="900px" align="center" border="0" cellpadding="0" cellspacing="0">
		<tr><td colspan="3"><br/><br/></td></tr>
		<tr class="totales">
			<td  width="70%">&nbsp;</td>
			<td width="15%">Total Cirugias:</td>
			<td><?php echo $totalCirugias ?>&nbsp;</td>
		</tr>
			<tr class="totales">
			<td  width="75%">&nbsp;</td>
			<td colspan="2">
				<hr/>
			</td>
		</tr>
		<tr class="totales">
			<td  width="70%">&nbsp;</td>
			<td width="15%">Total Cobrado:</td>
			<td><?php echo "$".number_format($totalPlus ,2,',','.')  ?>&nbsp;</td>
		</tr>
		<tr class="totales">
			<td  width="75%">&nbsp;</td>
			<td width="15%">Total A Cobrar:</td>
			<td><?php echo "$".number_format($totalImporte ,2,',','.')  ?>&nbsp;</td>
		</tr>
		<tr class="totales">
			<td  width="75%">&nbsp;</td>
			<td colspan="2">
				<hr/>
			</td>
		</tr>
		<tr class="totales">
			<td  width="75%">&nbsp;</td>
			<td width="15%">Total Recaudado:</td>
			<td><?php echo "$".number_format($totalPlus+$totalImporte ,2,',','.')  ?>&nbsp;</td>
		</tr>		

<?php 
if($_REQUEST[excel] != 'true'){
?>
	<div id="filtro">
			<tr class="totales">
				<td colspan="2" align="right">
					<br/><br/>
					<a onclick="imprimir()" href=""><small>Imprimir</small></a></td>
				<td align="center">
					<br/><br/>
					<small><a target="_blank" href="cirTotal.php?excel=true&fecha=<?php echo $_REQUEST['fecha']?>">Generar Excel</a></small>
				</td>
			</tr>
	</div>

	<script>
	function imprimir() {
		document.getElementById("filtro").innerHTML = "";
		window.print();	
	}
	</script>
<?php
}
?>
		</table>
	
</body>
</html>